import java.awt.*;
import java.util.Random;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;


/**
 * @author
 * Yannic Remmet                        196983
 * Tobias Trabelsi                      197112
 * Anna-Katharina Wickert       		197122
 */
public class RandomDrawing extends Canvas implements ActionListener{
		Frame drawFrame;
		Frame buttons;
		CircleSquare drawF;
		Button exit;
		Button clear;
		Button draw;
		

        public RandomDrawing()  {
                super();
                drawFrame = new Frame("Draw Frame");
                drawFrame.setSize(500,500);
             
                drawF = new CircleSquare();
                drawF.setBackground(Color.white);
                
                drawFrame.add(drawF);
                drawFrame.setVisible(true);
                
                drawF.draw();
                
                buttons = new Frame("Menu");
                exit = new Button("Exit");
                clear = new Button("Clear");
                draw = new Button("Draw");
                
                buttons.setLayout(new FlowLayout());
                buttons.add(exit);
                buttons.add(clear);
                buttons.add(draw);
                buttons.pack();
                
                exit.addActionListener(this);
                
                buttons.setVisible(true);
            
        }

 

        private static final long serialVersionUID = 6474800767383101261L;

	
        public void actionPerformed(ActionEvent e) {
    		if (e.getActionCommand().equals("Exit")){
    			System.exit(1);
    		}
    		if (e.getActionCommand().equals("Clear")){
    			drawF.repaint();
    		}
    		if (e.getActionCommand().equals("Draw")){
    			randomCirSq();
    		}
    		
    	}

        private void randomCirSq() {
        	Random number = new Random();
        	int figure = number.nextInt(2); // 0 for Circle 1 for Sqaure
        	int fill = number.nextInt(2); // 0 for filled 1 for outline
        	// Color
        	int r = number.nextInt(256); 
        	int g = number.nextInt(256);
        	int b = number.nextInt(256);
        	int z = number.nextInt(501); // maximum is 500 px, size
        	int x = number.nextInt(501);
        	int y = number.nextInt(501);
        
        	
        	if (figure == 0){
        		if (fill == 0){
        			drawF.drawCircleFilled(x, y, z, r, g, b);
        		}
        		else {
        			drawF.drawCircle(x, y, z, r, g, b);
        		}
        	}
        	else {
        		if (fill == 0){
        			drawF.drawSquare(x, y, z, r, g, b);
        		}
        		else {
        			drawF.drawSquareFilled(x, y, z, r, g, b);
        		}
        	}
        	
      
        }
} 